<template>
  <div class="container">

    <div>
      <van-nav-bar title="商圈云抖音直播预告"
                   left-text=""
                   @click-left="onClickLeft"
      />
    </div>

    <div>

      <van-form @submit="onSubmit">
        <div class="">
          <img src="../images/zbyg.png" width="95%" style="margin-left: 2.5%">
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import {saveReport,saveReportReadNum ,uploadShareImg,saveDkinfo} from 'api/api'
import {Toast} from 'vant'
export default {
  name: 'myquanzi',
  data() {
    return {
      xq1:'',
      xq2:'',
      xq3:'',
      xq4:'',
      xq5:'',
      xq6:'',
      xq7:'',
      xq8:'',
      xq9:'',
      xq10:'',
      agencyid:'',
      gsname:'',
      frname:'',
      frsfzh:'',
      dkje:'',
      ppname:'',
      phone:'',
      fileList:[],
      images:[],

    }
  },
  created() {



  },
  methods: {
    //识别操作系统
    viewczxt(){
      var u = navigator.userAgent, app = navigator.appVersion;
      var isXiaomi = u.indexOf('XiaoMi') > -1; // 小米手机
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; // 其它安卓
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios
      if (isAndroid) {
        return "Android"
      }else if (isIOS) {
        if(isXiaomi) {
          return  "Android"
        }else {
          return  "Ios"
        }
      }
    },

    onClickLeft() {
      this.$router.go(-1) // 返回上一层
    },

    onSubmit(){
      let param = {}
      param.agencyid = this.agencyid
      param.phone = this.phone
      param.frname = this.frname
      param.frsfzh = this.frsfzh
      param.gsname = this.gsname
      param.dkje = this.dkje
      param.ppname = this.ppname
      param.yyzzurl = this.images.toString()



      if(!param.frname){
        Toast.fail('请输入法人姓名')
        return
      }

      if(!param.frsfzh){
        Toast.fail('请输入法人身份证号')
        return
      }

      if(!param.gsname){
        Toast.fail('请输入公司名称')
        return
      }

      if(!param.dkje){
        Toast.fail('请输入贷款金额')
        return
      }

      if(!param.ppname){
        Toast.fail('请输入代理品牌')
        return
      }

      if(!param.phone){
        Toast.fail('请输入您的手机号，以便跟您联系')
        return
      }


      saveDkinfo(param).then(response => {
        if (response.code === 200) {
          //Toast.success('保存成功')
          this.$router.push({ path: '/success', query: {}})
        }else{
          Toast.fail(response.msg)
        }
      })

    },

    saveReportReadNum(){
      let param = {}
      param.dictType = 'report_readed'
      saveReportReadNum(param).then(response => {
        if (response.code === 200) {

        }else{
          // Toast.fail(response.msg)
        }
      })
    },


    /**
     * 删除附件
     * @param {*} e
     */
    delImgs:function(item){
      console.log(item)
      console.log(this.images)
      let that = this
      let images = that.images
      let length = images.length
      for(var i=0;i<length;i++){
        if(images[i] == item.item){
          that.images.splice(i,1)
        }
      }
    },

    selectTp(){
      window.postMessage('camera');
      document.getElementById("uploadfileid").click();
    },

    fileSelected() {
      var file = document.getElementById('uploadfileid').files[0];
      if (file) {
        var fileSize = 0;
        if (file.size > 1024 * 1024)
          fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
        else
          fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';

        console.log(file.name)
        console.log(fileSize)
        console.log(file.type)

        let formData = new FormData();
        formData.append("file", file);
        formData.append("type","quanzi")
        let fileList = []
        uploadShareImg(formData).then(response => {
          console.log(response)
          if(response.code == 200 ){
            fileList.push(response.data.url)
            this.images.push(response.data.url+'')
            this.fileList.concat(fileList)
            console.log(this.fileList)
            console.log(this.images)
          }
        });
      }
    }


  }

}
</script>

<style scoped>

.container{
  background-color: white;
  height: auto;
}

.columnr{
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
}

.rownr{
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-start;
  width: 100%;
  font-size: 16px;
}

.content{
  font-size: 16px;
  padding:10px;
  width: 80%;
}

.text{
  text-indent: 32px;
  padding-left: 10px;
  padding-right: 10px;
  font-size: 16px;
  padding-top: 10px;
  line-height: 200%;
}

.text1{
  padding-left: 10px;
  padding-right: 10px;
  font-size: 14px;
  padding-top: 15px;
  line-height: 200%;
}

.box {
  position: relative;
  display: inline-block;
  padding-left: 12px;
}
.box .clear {
  position: absolute;
  top: 0;
  right: 0;
}


</style>
